package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark1Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark1 extends BaseMark {

    LayoutWatermark1Binding binding;

    public Mark1(@NonNull Context context) {
        super(context);
    }

    public Mark1(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark1(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark1Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            update();
            hideView(binding.binding23);
            for (int i = 3; i < binding.binding4.getChildCount(); i++) {
                binding.binding4.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark1Binding.inflate(LayoutInflater.from(getContext()), this, true);
            update();
        }
    }

    @Override
    public void update() {
        setText(binding.binding2, "title", "工程记录", binding.binding2);
        setText(binding.binding3, "time", "2023.03.06\t10:28", binding.binding3);
        setTime(binding.binding3, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        setText(binding.binding6, "area", binding.binding5);
        setText(binding.binding8, "content", binding.binding7);
        setText(binding.binding10, "shigong", binding.binding9);
        setText(binding.binding12, "jianli", binding.binding11);
        setText(binding.binding14, "weather", "晴", binding.binding13);
        setText(binding.binding16, "didian", "在这里", binding.binding15);
        setText(binding.binding18, "haiba", binding.binding17);
        setText(binding.binding20, "jingwei", binding.binding19);
        setText(binding.binding22, "beizhu", binding.binding21);
        setText(binding.binding25, "jianshedanwei", binding.binding24);
        setText(binding.binding27, "jianlidanwei", binding.binding26);
        setText(binding.binding29, "shigongdanwei", binding.binding28);
        setText(binding.binding31, "shejidanwei", binding.binding30);
        setText(binding.binding33, "kanchadanwei", binding.binding32);

        super.update();
    }

    @Override
    protected String getTimeKey() {
        return "time";
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title", "项目名称"));
        list.add(new EditItem("time", "时间", true));
        list.add(new EditItem("area", "施工区域"));
        list.add(new EditItem("content", "施工内容"));
        list.add(new EditItem("shigong", "施工责任人"));
        list.add(new EditItem("jianli", "监理责任人"));
        list.add(new EditItem("weather", "天气"));
        list.add(new EditItem("didian", "地点"));
        list.add(new EditItem("haiba", "海拔"));
        list.add(new EditItem("jingwei", "经纬度"));
        list.add(new EditItem("beizhu", "备注"));
        list.add(new EditItem("jianshedanwei", "建设单位"));
        list.add(new EditItem("jianlidanwei", "监理单位"));
        list.add(new EditItem("shigongdanwei", "施工单位"));
        list.add(new EditItem("shejidanwei", "设计单位"));
        list.add(new EditItem("kanchadanwei", "勘察单位"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
